﻿using AutoMapper;
using B.S.Base.Write.API.Application.Command;
using MediatR;
using WEBAPI.Damoin;
using WEBAPI.ErroeCode;
using WEBAPI.Indaseture.Infasetures;

namespace B.S.Base.Write.API.Application.CommandHandLer
{
    public class AddApproveCommandHandLer : IRequestHandler<AddApproveCommand, APIResult<int>>
    {

        IBaseRepostiy<ApproveModel> _approveModel;
        IMapper _mapper;

        public AddApproveCommandHandLer(IBaseRepostiy<ApproveModel> approveModel, IMapper mapper)
        {
            _approveModel = approveModel;
            _mapper = mapper;
        }
        public async Task<APIResult<int>> Handle(AddApproveCommand request, CancellationToken cancellationToken)
        {
            var list = _mapper.Map<ApproveModel>(request);
            list.Statu = "待审批";
            await _approveModel.AddAsync(list);
            return new APIResult<int>
            {
                Code = ResultCode.Ok,
                Data = 1,
                Message = "添加成功"
            };
        }
    }
}
